MdTemplates.php
<?php
namespace Tlf\Scrawl\Test;
class MdTemplates extends \Tlf\Tester {
public function testBashInstall(){
$scrawl = new \Tlf\Scrawl();
$template = $scrawl->get_template('bash/install', ['scrawl-test', 'bin/scrawl-test']);
$this->str_contains(
$template,
'command="scrawl-test"',
'git clone https://gitlab.com/taeluf/php/CodeScrawl.git ${command}',
'chmod ug+x "${downloadDir}/${command}/bin/scrawl-test"',
);
}
public function testComposerInstall(){
$scrawl = new \Tlf\Scrawl();
$template = $scrawl->get_template('php/composer_install', ['taeluf/code-scrawl', 'v0.7.x-dev']);
$this->str_contains(
$template,
'composer require taeluf/code-scrawl v0.7.x-dev',
'"taeluf/code-scrawl": "v0.7.x-dev"',
);
}
public function testAstTemplates(){
$this->test('ast/method & ast/default templates');
$this->method_exists('Tlf\\Scrawl\\Test\\MdDocs', 'testAstVerb');
$this->test('ast/function_list template');
$scrawl = new \Tlf\Scrawl();
$php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
$ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);
$ast = $php_ext->parse_str(<<<PHP
<?php
/** abc test description */
function abc(){}
/** def test description */
function def(){}
PHP);
$ast['relPath'] = ':memory:';
$md = $scrawl->get_template('ast/function_list', ['file.memory', $ast, $ast_ext]);
$this->compare_lines(
'# File :memory:
## Functions
- `abc`: abc test description
- `def`: def test description',
$md
);
$this->test('ast/class template');
$scrawl = new \Tlf\Scrawl();
$php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
$ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);
$ast = $php_ext->parse_str(<<<PHP
<?php
class One {
/** sure const */
const sure = "sure";
/** abc var */
public \$abc = "okay";
/** def test description */
function def(){}
}
PHP);
$md = $scrawl->get_template('ast/class', ['class.One', $ast['class'][0], $ast_ext]);
$this->compare_lines(
'# class One
## Constants
- `const sure = "sure";`
## Properties
- `public $abc = "okay";` abc var
## Methods
- `function def()` def test description',
$md
);
$this->test('ast/class_methods');
$scrawl = new \Tlf\Scrawl();
$php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
$ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);
$ast = $php_ext->parse_str(<<<PHP
<?php
class One {
/** def test description */
function def(){}
function xyz(){}
}
PHP);
$md = $scrawl->get_template('ast/class_methods', ['class.One', $ast['class'][0], $ast_ext]);
$this->compare_lines(
'- `$one->def()`: def test description'
."\n".'- `$one->xyz()`:',
$md
);
}
}